/**
 * Created by yuweimei on 2018/3/28.
 */
app.controller('forget', function($scope, $http) {

	//用户邮箱
	$scope.email = '';
	//用户新密码
	$scope.newpassword = '';
	$scope.verificationCode = '';

	$scope.forgetEmailPassword = function() {
		var registerInfo = {
			'email': $scope.email,
			'newpassword': $scope.newpassword,
			'verificationCode': $scope.verificationCode
		};
		$http({
			method: 'post',
			url: app.netPath + '/users/resetPasswordByEmail',
			params: registerInfo
		}).then(function(res) {
			console.log(res);
			if(!res.data.error) {
				$.toast('密码重置成功')
				location.href = '#login'
			} else {
				$.toast(res.data.msg);
				return;
			}
		}, function() {
			$.toast('网络走丢了！')
		})
	};

	$scope.getVerificationCode = function() {
		var email = {
			'email': $scope.email
		};
		$http({
			method: 'get',
			url: app.netPath + '/users/getVerificationCode',
			params: email
		}).then(function(res) {
			if(!res.data.error) {
				$.toast('验证码发送成功');
			} else {
				$.toast("验证码发送失败");
			}
		}, function() {

			$.toast('网络有问题哟');
		})
	}
	$(".get_emil_code").click(function() {
		if($(".email_input input[ type='text']").val() == "") {
			$.toast("邮箱不能为空");
		} else if(!(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/).test($(".email_input input[ type='text']").val())) {

			$.toast("邮箱格式不正确！请重新输入");
			$(".email1").focus();

		} else {
			$scope.getVerificationCode();

		}

	})
})